import java.awt.event.KeyEvent;

public class RegexpManuelle {

  public static final char[] UN_OU_DEUX_PREMIERS_CHARS = new char[] { //
	  'j', //
      'J', //
      't', //
      'T', //
      'q', //
      'Q', //
      'k', //
      'K', //
      'a', //
      'A' //
  };

  public static final int TAILLE_TAB = UN_OU_DEUX_PREMIERS_CHARS.length;

  public static final boolean isIn(char c) {
    boolean result = false;
    for (int j = 0; j < TAILLE_TAB; j++) {
      if (c == UN_OU_DEUX_PREMIERS_CHARS[j]) {
        result = true;
        break;
      }
    }
    return result;
  }

  public static final boolean isOk1Ou2(char c) {
    return isNumerique(c) || isIn(c);
  }

  public static final char[] CHARS_SPECS = new char[] { //
	  KeyEvent.VK_BACK_SPACE, // backspace
      KeyEvent.VK_DELETE, //
      KeyEvent.VK_END, // End
      KeyEvent.VK_HOME, // Home
      KeyEvent.VK_RIGHT,  // fleche droite
      KeyEvent.VK_LEFT  // Fleche gauche
  };

  public static final int TAILLE_TAB_CHARS_SPECS = CHARS_SPECS.length;

  public static final boolean isInCarSpec(char c) {
//	System.out.println("the hex value of " + (int)c + " is: " + Integer.toHexString(c));  
  	
    boolean result = false;
    for (int j = 0; j < TAILLE_TAB_CHARS_SPECS; j++) {
      if (c == CHARS_SPECS[j]) {
//      	System.err.println("isInCarSpec");
        result = true;
        break;
      }
    }
    return result;
  }

  public static final boolean isDouble(String i_s) {
    return i_s.charAt(0) == i_s.charAt(1);
  }

  // si non double liste
  // si double S
  public static final boolean isOk3(char c) {
    return c == 's' || c == 'o' || c == 'S' || c == 'O';
  }

  public static final boolean isNumerique(char c) {
    return (c >= '2' && c <= '9');
  }

  public static final String verifieur(String i_sCaracteresDejaTapes, char caractereTape) {
    String result = "";
    
    if (i_sCaracteresDejaTapes != null) 
    {
      int nbCharTapes = i_sCaracteresDejaTapes.length();
      if (nbCharTapes < 2 && isOk1Ou2(caractereTape)) 
      {
        if (isInCarSpec(caractereTape))
        	result = null;
        else
        	result = String.valueOf(caractereTape);
      } else if (nbCharTapes == 2 && !isDouble(i_sCaracteresDejaTapes) && isOk3(caractereTape)) 
      {
        if (isInCarSpec(caractereTape))
        	result = null;
        else
        	result = String.valueOf(caractereTape);
      }
    }
    return result;
  }

  public static void main(String[] args) {
    StringBuilder resultat = new StringBuilder();
    resultat.append(verifieur(resultat.toString(), 'a'));
    resultat.append(verifieur(resultat.toString(), 'b'));
    resultat.append(verifieur(resultat.toString(), 'c'));
    resultat.append(verifieur(resultat.toString(), 'K'));
    resultat.append(verifieur(resultat.toString(), 'a'));
    resultat.append(verifieur(resultat.toString(), 'a'));
    resultat.append(verifieur(resultat.toString(), '1'));
    resultat.append(verifieur(resultat.toString(), '1'));
    resultat.append(verifieur(resultat.toString(), 'O'));
    resultat.append(verifieur(resultat.toString(), '1'));
    resultat.append(verifieur(resultat.toString(), 'K'));
    resultat.append(verifieur(resultat.toString(), 'K'));
    resultat.append(verifieur(resultat.toString(), '2'));

    System.out.println(resultat.toString());
  }

}